export default {
	//无token提示
	noToken() {
		uni.removeStorageSync('token');
		uni.removeStorageSync('userInfo');
		uni.showModal({
			title: '温馨提示',
			content: '请登录后再来继续浏览哦~',
			confirmText: '去登录',
			confirmColor: '#1C87F3',
			success: function(res) {
				if(res.confirm) {
					uni.navigateTo({
						url: '/pagesLogin/wxLogin/wxLogin'
					})
				}
			}
		})
	},
	
	//操作无token 提示
	handleToken() {
		uni.showModal({
			title: '温馨提示',
			content: '请登录后操作哦~',
			confirmText: '去登录',
			confirmColor: '#1C87F3',
			success: function(res) {
				if(res.confirm) {
					uni.navigateTo({
						url: '/pagesLogin/wxLogin/wxLogin'
					})
				}
			}
		})
	},
	
	//提示 请求中
	msgLoading: function(mask = true) {
		uni.showLoading({
			mask: mask
		});
	},
	
	//弹出提示
	msgShow: function(title, duration = 2000, mask = false, icon = 'none') {
		//统一提示方便全局修改
		if (Boolean(title) === false) {
			return;
		}
		uni.showToast({
			title,
			duration,
			mask,
			icon
		});
	},
	
	//跳转页面
	href: function(url, options = {}) {
		let type = options.type || 1; //跳转方式
		let ver = options.ver || false; //验证是否有该路由地址
		let params = options.params || false; //跳转携带参数
		let time = options.time || 0; //延迟跳转
		let msg = options.msg || ''; //提示文字
		let login = options.login || ''; //验证登录
		let token = uni.getStorageSync('token');
		if (!token && login) {
			this.goLogin();
			return false;
		}
		//type
		//1：navigateTo 保留当前页面，跳转到应用内的某个页面。(不可跳转到tabBar页面)
		//2：redirectTo 关闭当前页面，跳转到应用内的某个页面。(不可跳转到tabBar页面)
		//3：reLaunch   关闭所有页面，打开到应用内的某个页面。(可跳转到tabBar页面)
		//4：switchTab  跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面。
		if (ver) {
			if (!url) {
				this.msgShow('空地址')
				return false;
			}
		}
		//拼接参数
		if (params) {
			url = url + '?';
			for (let key in params) {
				url += key + '=' + params[key] + '&';
			}
			url = url.slice(0, url.length - 1);
		}
		//提示文字
		if (msg) {
			time = time || 1300;
			uni.showToast({
				title: msg,
				icon: 'none',
				mask: true,
				duration: time
			});
		}
		//跳转
		switch (type) {
			case 1:
				setTimeout(() => {
					uni.navigateTo({
						url: url
					})
				}, time)
				break;
			case 2:
				setTimeout(() => {
					uni.redirectTo({
						url: url
					})
				}, time)
				break;
			case 3:
				setTimeout(() => {
					uni.reLaunch({
						url: url
					})
				}, time)
				break;
			case 4:
				setTimeout(() => {
					uni.switchTab({
						url: url
					})
				}, time)
				break;
		}
	},
	
	//退出登录
	outFun() {
		uni.removeStorageSync('token');
		uni.removeStorageSync('userOpenId');
		uni.removeStorageSync('inviteCode')
		uni.switchTab({
			url: '/pages/home/home'
		})
	},
	
	
	//返回上一级
	pageBack: function(msg, delta = 1, time = 1300) {
		if (msg) {
			this.msgShow(msg);
		}
		setTimeout(function() {
			uni.navigateBack({
				delta: delta
			});
		}, time);
	},
	
	//必填验证
	IsEmpty: function(str) {
		return (str == null || str.length < 1) ? false : true;
	}
}